﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

public partial class census_score : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        int pass, sum;
        string Cno = Request.QueryString["Cno"];
        string Cname = Request.QueryString["Cname"];

        Label1.Text = Cname;

        string conn = "Data Source= . ;Initial Catalog=XSXK; User ID=sa; pwd=123";
        SqlConnection connection = new SqlConnection(conn);
        try
        {
            connection.Open();
            SqlCommand comm = new SqlCommand();
            comm.Connection = connection;

            string str_sql = " select COUNT(*) from result where result.Cno='"+Cno+"' and result.score>=60 and result.score<=100 ";
            comm.CommandText = str_sql;
            pass = Convert.ToInt32(comm.ExecuteScalar());

            str_sql = " select COUNT(*) from result where result.Cno='" + Cno + "' ";
            comm.CommandText = str_sql;
            sum = Convert.ToInt32(comm.ExecuteScalar());

            Label2.Text = Convert.ToString(pass*1.0 / sum * 100);
        }
        catch (SqlException ex)
        {
            Response.Write(ex.Message);
        }

        finally
        {
            connection.Close();//关闭数据库连接
        }
    }
}